﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FreeDream.Common.CacheTwoHelper
{
    /// <summary>
    /// 缓存接口(分别内存缓存和Redis缓存)
    /// </summary>
    public interface ICacheService
    {
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="key">缓存Key</param>
        /// <param name="value">缓存Value</param>
        /// <param name="ExpirtionTime">过期时间</param>
        /// <returns></returns>
        bool Add(string key, object value, int ExpirtionTime = 20);

        /// <summary>
        /// 设置缓存，并指定绝对超时时间
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="absoluteTimeoutSeconds">绝对超时时间</param>
        void SetValue<T>(string key, T value, int absoluteTimeoutSeconds);

        /// <summary>
        /// 设置缓存，并设定超时时间，不访问（滑动）超时时间
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="absoluteTimeoutSeconds">绝对超时时间</param>
        /// <param name="slidingExpirationSeconds">不访问超时时间（在这个指定的时段内没有使用则过期，否则顺延）</param>
        void SetValue<T>(string key, T value, int absoluteTimeoutSeconds, int slidingExpirationSeconds);

        /// <summary>
        /// 移除
        /// </summary>
        /// <param name="key">缓存Key</param>
        /// <returns></returns>
        bool Remove(string key);

        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        string GetValue(string key);

        /// <summary>
        /// 验证缓存项是否存在
        /// </summary>
        /// <param name="key">缓存Key</param>
        /// <returns></returns>
        bool Exists(string key);

    }
}
